home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glider 3.14 / source / Glider parts ƒ / B-AboutIt.p < prev    next >
Encoding:
Text File  |  1993-06-03  |  11.4 KB  |  291 lines  |  [TEXT/PJMM]

  1. unit AboutIt;
  2.  
  3. interface
  4.  
  5.     procedure D_MoreAboutGlider;
  6.     procedure Init_AboutIt;
  7.     procedure Close_AboutIt;
  8.     procedure Open_AboutIt;
  9.     procedure Update_AboutIt (whichWindow: WindowPtr);
  10.     procedure Do_AboutIt (myEvent: EventRecord; var theInput: TEHandle);
  11.  
  12. implementation
  13.  
  14.     const
  15.         I_Help = 7;    {Button ID}
  16.         I_More = 8;    {Button ID}
  17.         I_Okay = 1;
  18.         I_Static_Text = 2;
  19.         I_Static_Text3 = 3;
  20.         I_Static_Text5 = 4;
  21.         I_Static_Text7 = 5;
  22.         I_Static_Text9 = 6;
  23.         I_Static_Text11 = 7;
  24.         I_Static_Text13 = 8;
  25.         I_Static_Text15 = 9;
  26.         I_Static_Text17 = 10;
  27.         I_Static_Text19 = 11;
  28.         I_Static_Text21 = 12;
  29.         I_Static_Text23 = 13;
  30.         I_Static_Text25 = 14;
  31.         I_Static_Text27 = 15;
  32.         I_Static_Text29 = 16;
  33.         I_Static_Text31 = 17;
  34.         I_Static_Text33 = 18;
  35.         I_Static_Text35 = 19;
  36.         I_HelpPicture = 60;
  37.         I_Rectanglex43 = 26;
  38.  
  39.     var
  40.         ExitDialog: boolean;                {Flag used to exit the Dialog        }
  41.         MyWindow: WindowPtr;            {Window pointer                    }
  42.         tempRect: Rect;                    {Temporary rectangle            }
  43.         Index: Integer;                    {For looping                        }
  44.         CtrlHandle: controlhandle;        {Control handle                    }
  45.         sTemp: Str255;                    {Get text entered, temp holding    }
  46.  
  47. {=================================}
  48.  
  49.     function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
  50.         var
  51.             DoubleClick: boolean;                {Flag to say that a double click on a list happened}
  52.             MyPt: Point;                         {Current list selection point}
  53.             tempRect: Rect;
  54.  
  55.     begin
  56.         MyFilter := FALSE;
  57.         if (theEvent.what = MouseDown) then   {Only do on a mouse click}
  58.             begin
  59.                 MyPt := theEvent.where;             {Get the point where the mouse was clicked}
  60.                 with theDialog^.portBits.bounds do  {Do this way for speed}
  61.                     begin
  62.                         myPt.h := myPt.h + left;
  63.                         myPt.v := myPt.v + top;
  64.                     end;
  65.             end;
  66.     end;
  67.  
  68. {===========================================================}
  69.  
  70.     procedure D_Help;
  71.         var
  72.             GetSelection: DialogPtr;    {Name of dialog}
  73.             tempRect: Rect;            {Temporary tectangle}
  74.             DType: Integer;                {Type of dialog item}
  75.             Index: Integer;                {For looping}
  76.             DItem: Handle;                {Handle to the dialog item}
  77.             CItem, CTempItem: controlhandle;    {Control handle}
  78.             sTemp: Str255;            {Get text entered, temp holding}
  79.             itemHit: Integer;            {Get selection}
  80.             temp: Integer;                {Get selection, temp holding}
  81.             ThisEditText: TEHandle;    {Handle to get the Dialogs TE record}
  82.             TheDialogPtr: DialogPeek;{Pointer to Dialogs definition record, contains the TE record}
  83.  
  84.         procedure Refresh_Dialog;
  85.             var
  86.                 rTempRect: Rect;
  87.         begin
  88.             PenNormal;
  89.             GetDItem(GetSelection, I_Okay, DType, DItem, tempRect);{Get the item handle}
  90.             PenSize(3, 3);                  {Change pen to draw thick default outline}
  91.             InsetRect(tempRect, -4, -4);        {Draw outside the button by 1 pixel}
  92.             FrameRoundRect(tempRect, 16, 16); {Draw the outline}
  93.             PenSize(1, 1);
  94.         end;
  95.  
  96.     begin
  97.         GetSelection := GetNewDialog(4, nil, Pointer(-1)); {Bring in the dialog resource}
  98.         tempRect := GetSelection^.portRect;    {Get window size, we will now center it}
  99.         tempRect.Top := ((screenBits.Bounds.Bottom - screenBits.Bounds.Top) - (tempRect.Bottom - tempRect.Top)) div 2;
  100.         tempRect.Left := ((screenBits.Bounds.Right - screenBits.Bounds.Left) - (tempRect.Right - tempRect.Left)) div 2;
  101.         MoveWindow(GetSelection, tempRect.Left, tempRect.Top, TRUE);{Now move the window to the proper position}
  102.         ShowWindow(GetSelection);             {Open a dialog box}
  103.         SelectWindow(GetSelection);           {Lets see it}
  104.         SetPort(GetSelection);                {Perpare to add conditional text}
  105.         Refresh_Dialog;            {Draw any Lists, lines, or rectangles}
  106.         ExitDialog := FALSE;    {Do not exit dialog handle loop yet}
  107.         repeat
  108.             ModalDialog(nil, itemHit);        {Wait until an item is hit}
  109.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  110.             CItem := Pointer(DItem);            {Get the control handle}
  111.             if (ItemHit = I_Okay) then        {Handle the Button being pressed}
  112.                 begin
  113.                     ExitDialog := TRUE;                {Exit the dialog when this selection is made}
  114.                     Refresh_Dialog;
  115.                 end;                                {End for this item selected}
  116.         until ExitDialog;                        {Handle dialog items until exit selected}
  117.         DisposDialog(GetSelection);        {Flush the dialog out of memory}
  118.     end;
  119.  
  120. {=================================}
  121.  
  122.     procedure D_MoreAboutGlider;
  123.         var
  124.             GetSelection: DialogPtr;             {Name of dialog}
  125.             tempRect: Rect;                      {Temporary tectangle}
  126.             DType: Integer;                      {Type of dialog item}
  127.             Index: Integer;                      {For looping}
  128.             DItem: Handle;                       {Handle to the dialog item}
  129.             CItem, CTempItem: controlhandle;     {Control handle}
  130.             sTemp: Str255;                       {Get text entered, temp holding}
  131.             itemHit: Integer;                    {Get selection}
  132.             temp: Integer;                       {Get selection, temp holding}
  133.             ThisEditText: TEHandle;              {Handle to get the Dialogs TE record}
  134.             TheDialogPtr: DialogPeek;            {Pointer to Dialogs definition record, contains the TE record}
  135.  
  136.         procedure Refresh_Dialog;               {Refresh the dialogs non-controls}
  137.             var
  138.                 rTempRect: Rect;                       {Temp rectangle used for drawing}
  139.         begin
  140.             PenNormal;
  141.             GetDItem(GetSelection, I_Okay, DType, DItem, tempRect);{Get the item handle}
  142.             PenSize(3, 3);                  {Change pen to draw thick default outline}
  143.             InsetRect(tempRect, -4, -4);        {Draw outside the button by 1 pixel}
  144.             FrameRoundRect(tempRect, 16, 16); {Draw the outline}
  145.             PenSize(1, 1);
  146.         end;
  147.  
  148.     begin                                   {Start of dialog handler}
  149.         GetSelection := GetNewDialog(3, nil, Pointer(-1)); {Bring in the dialog resource}
  150.         tempRect := GetSelection^.portRect;    {Get window size, we will now center it}
  151.         tempRect.Top := ((screenBits.Bounds.Bottom - screenBits.Bounds.Top) - (tempRect.Bottom - tempRect.Top)) div 2;
  152.         tempRect.Left := ((screenBits.Bounds.Right - screenBits.Bounds.Left) - (tempRect.Right - tempRect.Left)) div 2;
  153.         MoveWindow(GetSelection, tempRect.Left, tempRect.Top, TRUE);{Now move the window to the proper position}
  154.         ShowWindow(GetSelection);             {Open a dialog box}
  155.         SelectWindow(GetSelection);           {Lets see it}
  156.         SetPort(GetSelection);                {Perpare to add conditional text}
  157.  
  158.         Refresh_Dialog;
  159.         ExitDialog := FALSE;                    {Do not exit dialog handle loop yet}
  160.         repeat                                {Start of dialog handle loop}
  161.             ModalDialog(nil, itemHit);          {Wait until an item is hit}
  162.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  163.             CItem := Pointer(DItem);            {Get the control handle}
  164.             if (ItemHit = I_Okay) then           {Handle the Button being pressed}
  165.                 begin
  166.                     ExitDialog := TRUE;                 {Exit the dialog when this selection is made}
  167.                 end;                                {End for this item selected}
  168.         until ExitDialog;                     {Handle dialog items until exit selected}
  169.         DisposDialog(GetSelection);           {Flush the dialog out of memory}
  170.     end;
  171.  
  172. {=================================}
  173.  
  174.     procedure Init_AboutIt;
  175.     begin
  176.         MyWindow := nil;                {Make sure other routines know we are not valid yet}
  177.     end;
  178.  
  179. {=================================}
  180.  
  181.     procedure Close_AboutIt;
  182.     begin
  183.         DisposeWindow(MyWindow);    {Clear window and controls}
  184.         MyWindow := nil;                {Make sure other routines know we are open}
  185.     end;
  186.  
  187. {=================================}
  188.  
  189.     procedure UpDate_AboutIt;
  190.         var
  191.             SavePort: WindowPtr;    {Place to save the last port}
  192.             Icon_Handle: Handle;        {Icon handle for icon loaded and displayed}
  193.             sTemp: Str255;            {Temporary string}
  194.     begin
  195.         if (MyWindow <> nil) and (MyWindow = whichWindow) then {Handle an open when already opened}
  196.             begin
  197.                 GetPort(SavePort);                            {Save the current port}
  198.                 SetPort(MyWindow);                            {Set the port to my window}
  199.                 Icon_Handle := GetIcon(11);                {Get Icon into memory}
  200.                 SetRect(tempRect, 331, 10, 363, 42);    {left,top,right,bottom}
  201.                 if (Icon_Handle <> nil) then                {Only use handle if it is valid}
  202.                     PlotIcon(tempRect, Icon_Handle);        {Draw the icon in the window}
  203.                 TextFont(systemFont);                        {Set the font to draw in}
  204.                 SetRect(tempRect, 11, 15, 90, 30);
  205.                 sTemp := 'Glider+ 3.14';
  206.                 TextBox(Pointer(ord(@sTemp) + 1), length(sTemp), tempRect, teJustLeft);
  207.                 SetRect(tempRect, 11, 50, 362, 66);
  208.                 sTemp := '®1989, 90, 91 john calhoun - Soft Dorothy Software';
  209.                 TextBox(Pointer(ord(@sTemp) + 1), length(sTemp), tempRect, teJustLeft);
  210.                 DrawControls(MyWindow);                                {Draw all the controls                }
  211.                 SetPort(SavePort);                                        {Restore the old port                }
  212.             end;                                                            {End for if (MyWindow<>nil)        }
  213.     end;
  214.  
  215. {=================================}
  216.  
  217.     procedure Open_AboutIt;
  218.     begin
  219.         if (MyWindow = nil) then                                    {Handle an open when already opened}
  220.             begin
  221.                 MyWindow := GetNewWindow(2, nil, Pointer(-1));    {Get the window from the resource file}
  222.                 MoveWindow(MyWindow, (screenBits.bounds.right - 384) div 2, (screenBits.bounds.bottom - 200) div 2 + 20, FALSE);
  223.                 ShowWindow(MyWindow);
  224.                 SelectWindow(MyWindow);                                 {Bring our window to the front}
  225.                 SetPort(MyWindow);                                        {Prepare to write into our window}
  226.                 CtrlHandle := GetNewControl(I_Help, MyWindow);    {Make a new button                        }
  227.                 CtrlHandle := GetNewControl(I_More, MyWindow);    {Make a new button                        }
  228.                 UpDate_AboutIt(MyWindow);                            {Do an update to draw rest of items    }
  229.             end
  230.         else
  231.             SelectWindow(MyWindow);                                {Already open, so show it                }
  232.     end;
  233.  
  234. {=================================}
  235.  
  236.     procedure Do_AboutIt;
  237.         var
  238.             RefCon: integer;                       {RefCon for controls}
  239.             code: integer;                         {Location of event in window or controls}
  240.             theValue: integer;                     {Current value of a control}
  241.             whichWindow: WindowPtr;                {Window pointer where event happened}
  242.             myPt: Point;                           {Point where event happened}
  243.             theControl: ControlHandle;             {Handle for a control}
  244.  
  245.         procedure Do_A_Button;                  {Handle a button being pressed}
  246.         begin
  247.             HiliteControl(theControl, 10);        {Darken the button}
  248.             RefCon := GetCRefCon(theControl);     {get control refcon}
  249.             case RefCon of                        {Select correct button}
  250.                 I_Help:                            {Help, button        }
  251.                     begin
  252.                         D_Help;                        {Call a dialog        }
  253.                     end;
  254.                 I_More:                        {More, button    }
  255.                     begin
  256.                         D_MoreAboutGlider;        {Call a dialog        }
  257.                     end;
  258.                 otherwise
  259.                     begin
  260.                     end;
  261.             end;                                {end of case        }
  262.             HiliteControl(theControl, 0);    {Lighten the button}
  263.         end;
  264.  
  265.     begin
  266.         if (MyWindow <> nil) then    {Handle only when the window is valid}
  267.             begin
  268.                 code := FindWindow(myEvent.where, whichWindow); {Get where in window and which window}
  269.                 if (myEvent.what = MouseDown) and (MyWindow = whichWindow) then {}
  270.                     begin
  271.                         myPt := myEvent.where;                {Get mouse position}
  272.                         with MyWindow^.portBits.bounds do    {Make it relative}
  273.                             begin
  274.                                 myPt.h := myPt.h + left;
  275.                                 myPt.v := myPt.v + top;
  276.                             end;
  277.                     end;
  278.                 if (MyWindow = whichWindow) and (code = inContent) then {for our window    }
  279.                     begin
  280.                         code := FindControl(myPt, whichWindow, theControl);    {Get type of control    }
  281.                         if (code <> 0) then        {Check type of control}
  282.                             code := TrackControl(theControl, myPt, nil);            {Track the control    }
  283.                         if code = inButton then
  284.                             Do_A_Button;                                                {Do buttons            }
  285.                     end;                                        {End for if (MyWindow=whichWindow)    }
  286.             end;                                            {End for if (MyWindow<>nil)                }
  287.     end;
  288.  
  289. {=================================}
  290.  
  291. end.                                    {End of unit}